package com.hb.game.pk.ui.fragment;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.FutureTarget;
import com.hb.game.pk.R;
import com.hb.game.pk.api.Host;
import com.hb.game.pk.base.BaseFragment;
import com.hb.game.pk.utils.ScreenUtils;
import com.hb.game.pk.widgets.titlebar.TitleBar;

import java.util.concurrent.ExecutionException;

import butterknife.BindView;

public class MainFragment extends BaseFragment {
    @BindView(R.id.title_bar)
    TitleBar titleBar;
    @BindView(R.id.iv_main)
    ImageView ivMain;
    private Thread thread;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_main;
    }

    @Override
    protected int getListViewId() {
        return 0;
    }

    @Override
    protected int getRefreshId() {
        return 0;
    }

    @Override
    protected void init(View view, Bundle savedInstanceState) {
        super.init(view, savedInstanceState);
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        super.initView(view, savedInstanceState);

        thread = new Thread() {
            @Override
            public void run() {
                super.run();
                try {
                    FutureTarget<Drawable> into = Glide.with(mActivity).load(Host.HOST + "src/00.jpg").into(ScreenUtils.getScreenWidth(mActivity), ScreenUtils.getScreenHeight(mActivity));
                    final Drawable drawable = into.get();
                    mActivity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            ivMain.setBackground(drawable);
                        }
                    });
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (ExecutionException e) {
                    e.printStackTrace();
                }
            }
        };
        thread.start();
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void onStop() {
        super.onStop();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (thread != null) {
            thread.stop();
        }
    }
}
